import 'package:flutter/material.dart';

// 引入页面
import 'pages/Example_01.dart';
import 'pages/Example_02.dart';
import 'pages/Example_03.dart';
import 'pages/Example_04.dart';
import 'pages/Example_05.dart';
import 'pages/Example_06.dart';
import 'pages/Example_07.dart';
void main() {
  runApp(const Generate());
}

class Generate extends StatelessWidget {
  const Generate({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'First App',
      theme: ThemeData(
        appBarTheme: const AppBarTheme(
          backgroundColor: Color(0xff0A0E21), // AppBar 背景色设置为红色
        ),
        scaffoldBackgroundColor: Color(0xff0A0E21)
      ),
      home: const MyApp()
    );
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("学习样例集合")
        ),
        body: Padding(
          padding: const EdgeInsets.all(12.0),
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                MainBlock(
                  colour1: Colors.teal[300],
                  colour2: Colors.teal,
                  title: '布局widget练习',
                  actualTitle: '查看布局实例',
                  example: Example_01()
                ),
                MainBlock(
                  colour1: Colors.red[300],
                  colour2: Colors.red,
                  title: '摇骰子小练习',
                  actualTitle: '摇骰子小游戏',
                  example: Example_02()
                ),
                MainBlock(
                  colour1: Colors.purple[300],
                  colour2: Colors.purple,
                  title: '音乐app小练习',
                  actualTitle: '木琴演奏app',
                  example: Example_03()
                ),
                MainBlock(
                  colour1: Colors.yellow[300],
                  colour2: Colors.yellow,
                  title: '试卷调查小应用',
                  actualTitle: '试卷调查app',
                  example: Example_04()
                ),
                MainBlock(
                  colour1: Colors.green[300],
                  colour2: Colors.green,
                  title: '计算器小应用',
                  actualTitle: '计算器app',
                  example: Example_05()
                ),
                MainBlock(
                    colour1: Colors.lightBlueAccent,
                    colour2: Colors.lightBlueAccent,
                    title: '天气预报应用',
                    actualTitle: '天气预报app',
                    example: Example_06()
                ),
                MainBlock(
                    colour1: Colors.deepOrange,
                    colour2: Colors.deepOrange,
                    title: '动画部分',
                    actualTitle: '自定义动画',
                    example: Example_07()
                ),
              ],
            ),
          ),
        )
    );
  }
}

class MainBlock extends StatelessWidget {
  MainBlock({this.colour1, this.colour2, this.title, this.actualTitle, this.example});

  Color? colour1;
  Color? colour2;
  String? title;
  String? actualTitle;
  Widget? example;

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          width: 340.0,
          padding: EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
          margin: EdgeInsets.symmetric(vertical: 0, horizontal: 10.0),
          decoration: BoxDecoration(
            color: colour1, // 设置背景颜色
            borderRadius: BorderRadius.circular(6.0), // 设置边界半径（圆角）
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(title!),
              ElevatedButton(
                child: Text(actualTitle!),
                style: ElevatedButton.styleFrom(
                  backgroundColor: colour2, // 设置背景色为绿色
                ),
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(builder: (context) => example!)
                  );
                },
              ),
            ],
          ),
        ),
        const SizedBox(height: 10.0)
      ]
    );
  }
}

